.class public Lorg/microemu/app/classloader/MIDletClassLoader;
.super Ljava/net/URLClassLoader;
.source "MIDletClassLoader.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lorg/microemu/app/classloader/MIDletClassLoader$LoadClassByParentException;
    }
.end annotation


# static fields
.field private static final debug:Z

.field public static enhanceCatchBlock:Z

.field public static instrumentMIDletClasses:Z

.field public static traceClassLoading:Z

.field public static traceSystemClassLoading:Z


# instance fields
.field private acc:Ljava/security/AccessControlContext;

.field private config:Lorg/microemu/app/classloader/InstrumentationConfig;

.field private delegatingToParent:Z

.field private findPathInParent:Z

.field private noPreporcessingNames:Ljava/util/Set;


# direct methods
.method static constructor <clinit>()V
    .locals 2

    .prologue
    const/4 v1, 0x0

    .line 59
    const/4 v0, 0x1

    sput-boolean v0, Lorg/microemu/app/classloader/MIDletClassLoader;->instrumentMIDletClasses:Z

    .line 61
    sput-boolean v1, Lorg/microemu/app/classloader/MIDletClassLoader;->traceClassLoading:Z

    .line 63
    sput-boolean v1, Lorg/microemu/app/classloader/MIDletClassLoader;->traceSystemClassLoading:Z

    .line 65
    sput-boolean v1, Lorg/microemu/app/classloader/MIDletClassLoader;->enhanceCatchBlock:Z

    return-void
.end method

.method public constructor <init>(Ljava/lang/ClassLoader;)V
    .locals 2
    .parameter "parent"

    .prologue
    const/4 v1, 0x0

    .line 91
    new-array v0, v1, [Ljava/net/URL;

    invoke-direct {p0, v0, p1}, Ljava/net/URLClassLoader;-><init>([Ljava/net/URL;Ljava/lang/ClassLoader;)V

    .line 69
    iput-boolean v1, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->delegatingToParent:Z

    .line 71
    iput-boolean v1, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->findPathInParent:Z

    .line 92
    new-instance v0, Ljava/util/HashSet;

    invoke-direct {v0}, Ljava/util/HashSet;-><init>()V

    iput-object v0, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->noPreporcessingNames:Ljava/util/Set;

    .line 93
    invoke-static {}, Ljava/security/AccessController;->getContext()Ljava/security/AccessControlContext;

    move-result-object v0

    iput-object v0, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->acc:Ljava/security/AccessControlContext;

    .line 94
    new-instance v0, Lorg/microemu/app/classloader/InstrumentationConfig;

    invoke-direct {v0}, Lorg/microemu/app/classloader/InstrumentationConfig;-><init>()V

    iput-object v0, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->config:Lorg/microemu/app/classloader/InstrumentationConfig;

    .line 95
    iget-object v0, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->config:Lorg/microemu/app/classloader/InstrumentationConfig;

    sget-boolean v1, Lorg/microemu/app/classloader/MIDletClassLoader;->enhanceCatchBlock:Z

    invoke-virtual {v0, v1}, Lorg/microemu/app/classloader/InstrumentationConfig;->setEnhanceCatchBlock(Z)V

    .line 96
    iget-object v0, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->config:Lorg/microemu/app/classloader/InstrumentationConfig;

    const/4 v1, 0x1

    invoke-virtual {v0, v1}, Lorg/microemu/app/classloader/InstrumentationConfig;->setEnhanceThreadCreation(Z)V

    .line 97
    return-void
.end method

.method static access$000(Lorg/microemu/app/classloader/MIDletClassLoader;)Z
    .locals 1
    .parameter "x0"

    .prologue
    .line 55
    iget-boolean v0, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->delegatingToParent:Z

    return v0
.end method

.method public static getClassResourceName(Ljava/lang/String;)Ljava/lang/String;
    .locals 2
    .parameter "className"

    .prologue
    .line 331
    const/16 v0, 0x2e

    const/16 v1, 0x2f

    invoke-virtual {p0, v0, v1}, Ljava/lang/String;->replace(CC)Ljava/lang/String;

    move-result-object v0

    const-string v1, ".class"

    invoke-virtual {v0, v1}, Ljava/lang/String;->concat(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method static getClassURL(Ljava/lang/ClassLoader;Ljava/lang/String;)Ljava/net/URL;
    .locals 7
    .parameter "parent"
    .parameter "className"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/net/MalformedURLException;
        }
    .end annotation

    .prologue
    .line 143
    invoke-static {p1}, Lorg/microemu/app/classloader/MIDletClassLoader;->getClassResourceName(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    .line 144
    .local v1, resource:Ljava/lang/String;
    invoke-virtual {p0, v1}, Ljava/lang/ClassLoader;->getResource(Ljava/lang/String;)Ljava/net/URL;

    move-result-object v2

    .line 145
    .local v2, url:Ljava/net/URL;
    if-nez v2, :cond_0

    .line 146
    new-instance v3, Ljava/net/MalformedURLException;

    new-instance v4, Ljava/lang/StringBuffer;

    invoke-direct {v4}, Ljava/lang/StringBuffer;-><init>()V

    const-string v5, "Unable to find class "

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {v4, p1}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    const-string v5, " URL"

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-direct {v3, v4}, Ljava/net/MalformedURLException;-><init>(Ljava/lang/String;)V

    throw v3

    .line 148
    :cond_0
    invoke-virtual {v2}, Ljava/net/URL;->toExternalForm()Ljava/lang/String;

    move-result-object v0

    .line 149
    .local v0, path:Ljava/lang/String;
    new-instance v3, Ljava/net/URL;

    const/4 v4, 0x0

    invoke-virtual {v0}, Ljava/lang/String;->length()I

    move-result v5

    invoke-virtual {v1}, Ljava/lang/String;->length()I

    move-result v6

    sub-int/2addr v5, v6

    invoke-virtual {v0, v4, v5}, Ljava/lang/String;->substring(II)Ljava/lang/String;

    move-result-object v4

    invoke-direct {v3, v4}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    return-object v3
.end method


# virtual methods
.method public addClassURL(Ljava/lang/String;)V
    .locals 7
    .parameter "className"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/net/MalformedURLException;
        }
    .end annotation

    .prologue
    .line 127
    invoke-static {p1}, Lorg/microemu/app/classloader/MIDletClassLoader;->getClassResourceName(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    .line 128
    .local v1, resource:Ljava/lang/String;
    invoke-virtual {p0}, Lorg/microemu/app/classloader/MIDletClassLoader;->getParent()Ljava/lang/ClassLoader;

    move-result-object v3

    invoke-virtual {v3, v1}, Ljava/lang/ClassLoader;->getResource(Ljava/lang/String;)Ljava/net/URL;

    move-result-object v2

    .line 129
    .local v2, url:Ljava/net/URL;
    if-nez v2, :cond_0

    .line 130
    invoke-virtual {p0, v1}, Lorg/microemu/app/classloader/MIDletClassLoader;->getResource(Ljava/lang/String;)Ljava/net/URL;

    move-result-object v2

    .line 132
    :cond_0
    if-nez v2, :cond_1

    .line 133
    new-instance v3, Ljava/net/MalformedURLException;

    new-instance v4, Ljava/lang/StringBuffer;

    invoke-direct {v4}, Ljava/lang/StringBuffer;-><init>()V

    const-string v5, "Unable to find class "

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {v4, p1}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    const-string v5, " URL"

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-direct {v3, v4}, Ljava/net/MalformedURLException;-><init>(Ljava/lang/String;)V

    throw v3

    .line 135
    :cond_1
    invoke-virtual {v2}, Ljava/net/URL;->toExternalForm()Ljava/lang/String;

    move-result-object v0

    .line 139
    .local v0, path:Ljava/lang/String;
    new-instance v3, Ljava/net/URL;

    const/4 v4, 0x0

    invoke-virtual {v0}, Ljava/lang/String;->length()I

    move-result v5

    invoke-virtual {v1}, Ljava/lang/String;->length()I

    move-result v6

    sub-int/2addr v5, v6

    invoke-virtual {v0, v4, v5}, Ljava/lang/String;->substring(II)Ljava/lang/String;

    move-result-object v4

    invoke-direct {v3, v4}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    invoke-virtual {p0, v3}, Lorg/microemu/app/classloader/MIDletClassLoader;->addURL(Ljava/net/URL;)V

    .line 140
    return-void
.end method

.method public addURL(Ljava/net/URL;)V
    .locals 0
    .parameter "url"

    .prologue
    .line 156
    invoke-super {p0, p1}, Ljava/net/URLClassLoader;->addURL(Ljava/net/URL;)V

    .line 157
    return-void
.end method

.method public classLoadByParent(Ljava/lang/String;)Z
    .locals 2
    .parameter "className"

    .prologue
    const/4 v1, 0x1

    .line 295
    const-string v0, "java."

    invoke-virtual {p1, v0}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_0

    move v0, v1

    .line 314
    :goto_0
    return v0

    .line 301
    :cond_0
    const-string v0, "sun.reflect."

    invoke-virtual {p1, v0}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_1

    move v0, v1

    .line 302
    goto :goto_0

    .line 305
    :cond_1
    const-string v0, "javax.microedition."

    invoke-virtual {p1, v0}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_2

    move v0, v1

    .line 306
    goto :goto_0

    .line 308
    :cond_2
    const-string v0, "javax."

    invoke-virtual {p1, v0}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z

    move-result v0

    if-eqz v0, :cond_3

    move v0, v1

    .line 309
    goto :goto_0

    .line 311
    :cond_3
    iget-object v0, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->noPreporcessingNames:Ljava/util/Set;

    invoke-interface {v0, p1}, Ljava/util/Set;->contains(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_4

    move v0, v1

    .line 312
    goto :goto_0

    .line 314
    :cond_4
    const/4 v0, 0x0

    goto :goto_0
.end method

.method public configure(Lorg/microemu/app/classloader/MIDletClassLoaderConfig;Z)V
    .locals 9
    .parameter "clConfig"
    .parameter "forJad"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/net/MalformedURLException;
        }
    .end annotation

    .prologue
    const/4 v8, 0x0

    const/4 v7, 0x1

    .line 105
    iget-object v4, p1, Lorg/microemu/app/classloader/MIDletClassLoaderConfig;->appclasspath:Ljava/util/List;

    invoke-interface {v4}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, iter:Ljava/util/Iterator;
    :cond_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-eqz v4, :cond_1

    .line 106
    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Ljava/lang/String;

    .line 107
    .local v2, path:Ljava/lang/String;
    new-instance v3, Ljava/util/StringTokenizer;

    sget-object v4, Ljava/io/File;->pathSeparator:Ljava/lang/String;

    invoke-direct {v3, v2, v4}, Ljava/util/StringTokenizer;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    .line 108
    .local v3, st:Ljava/util/StringTokenizer;
    :goto_0
    invoke-virtual {v3}, Ljava/util/StringTokenizer;->hasMoreTokens()Z

    move-result v4

    if-eqz v4, :cond_0

    .line 109
    new-instance v4, Ljava/net/URL;

    new-instance v5, Ljava/io/File;

    invoke-virtual {v3}, Ljava/util/StringTokenizer;->nextToken()Ljava/lang/String;

    move-result-object v6

    invoke-direct {v5, v6}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    invoke-static {v5}, Lorg/microemu/app/util/IOUtils;->getCanonicalFileClassLoaderURL(Ljava/io/File;)Ljava/lang/String;

    move-result-object v5

    invoke-direct {v4, v5}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    invoke-virtual {p0, v4}, Lorg/microemu/app/classloader/MIDletClassLoader;->addURL(Ljava/net/URL;)V

    goto :goto_0

    .line 112
    .end local v2           #path:Ljava/lang/String;
    .end local v3           #st:Ljava/util/StringTokenizer;
    :cond_1
    iget-object v4, p1, Lorg/microemu/app/classloader/MIDletClassLoaderConfig;->appclasses:Ljava/util/List;

    invoke-interface {v4}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v1

    :goto_1
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-eqz v4, :cond_2

    .line 113
    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v4

    check-cast v4, Ljava/lang/String;

    invoke-virtual {p0, v4}, Lorg/microemu/app/classloader/MIDletClassLoader;->addClassURL(Ljava/lang/String;)V

    goto :goto_1

    .line 115
    :cond_2
    invoke-virtual {p1, p2}, Lorg/microemu/app/classloader/MIDletClassLoaderConfig;->getDelegationType(Z)I

    move-result v0

    .line 116
    .local v0, delegationType:I
    const/4 v4, 0x2

    if-ne v0, v4, :cond_3

    move v4, v7

    :goto_2
    iput-boolean v4, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->delegatingToParent:Z

    .line 117
    if-ne v0, v7, :cond_4

    move v4, v7

    :goto_3
    iput-boolean v4, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->findPathInParent:Z

    .line 118
    return-void

    :cond_3
    move v4, v8

    .line 116
    goto :goto_2

    :cond_4
    move v4, v8

    .line 117
    goto :goto_3
.end method

.method public disableClassPreporcessing(Ljava/lang/Class;)V
    .locals 1
    .parameter "klass"

    .prologue
    .line 323
    invoke-virtual {p1}, Ljava/lang/Class;->getName()Ljava/lang/String;

    move-result-object v0

    invoke-virtual {p0, v0}, Lorg/microemu/app/classloader/MIDletClassLoader;->disableClassPreporcessing(Ljava/lang/String;)V

    .line 324
    return-void
.end method

.method public disableClassPreporcessing(Ljava/lang/String;)V
    .locals 1
    .parameter "className"

    .prologue
    .line 327
    iget-object v0, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->noPreporcessingNames:Ljava/util/Set;

    invoke-interface {v0, p1}, Ljava/util/Set;->add(Ljava/lang/Object;)Z

    .line 328
    return-void
.end method

.method protected findClass(Ljava/lang/String;)Ljava/lang/Class;
    .locals 13
    .parameter "name"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/ClassNotFoundException;
        }
    .end annotation

    .prologue
    const/4 v12, 0x0

    .line 338
    invoke-virtual {p0, p1}, Lorg/microemu/app/classloader/MIDletClassLoader;->classLoadByParent(Ljava/lang/String;)Z

    move-result v9

    if-eqz v9, :cond_0

    .line 339
    new-instance v9, Lorg/microemu/app/classloader/MIDletClassLoader$LoadClassByParentException;

    invoke-direct {v9, p1}, Lorg/microemu/app/classloader/MIDletClassLoader$LoadClassByParentException;-><init>(Ljava/lang/String;)V

    throw v9

    .line 343
    :cond_0
    :try_start_0
    new-instance v9, Lorg/microemu/app/classloader/MIDletClassLoader$3;

    invoke-direct {v9, p0, p1}, Lorg/microemu/app/classloader/MIDletClassLoader$3;-><init>(Lorg/microemu/app/classloader/MIDletClassLoader;Ljava/lang/String;)V

    iget-object v10, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->acc:Ljava/security/AccessControlContext;

    invoke-static {v9, v10}, Ljava/security/AccessController;->doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;

    move-result-object v5

    check-cast v5, Ljava/io/InputStream;

    .line 350
    .local v5, is:Ljava/io/InputStream;
    if-nez v5, :cond_1

    iget-boolean v9, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->findPathInParent:Z
    :try_end_0
    .catch Ljava/security/PrivilegedActionException; {:try_start_0 .. :try_end_0} :catch_1

    if-eqz v9, :cond_1

    .line 353
    :try_start_1
    invoke-virtual {p0, p1}, Lorg/microemu/app/classloader/MIDletClassLoader;->addClassURL(Ljava/lang/String;)V
    :try_end_1
    .catch Ljava/net/MalformedURLException; {:try_start_1 .. :try_end_1} :catch_0
    .catch Ljava/security/PrivilegedActionException; {:try_start_1 .. :try_end_1} :catch_1

    .line 354
    const/4 v3, 0x1

    .line 358
    .local v3, classFound:Z
    :goto_0
    if-eqz v3, :cond_1

    .line 359
    :try_start_2
    new-instance v9, Lorg/microemu/app/classloader/MIDletClassLoader$4;

    invoke-direct {v9, p0, p1}, Lorg/microemu/app/classloader/MIDletClassLoader$4;-><init>(Lorg/microemu/app/classloader/MIDletClassLoader;Ljava/lang/String;)V

    iget-object v10, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->acc:Ljava/security/AccessControlContext;

    invoke-static {v9, v10}, Ljava/security/AccessController;->doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;

    move-result-object v5

    .end local v5           #is:Ljava/io/InputStream;
    check-cast v5, Ljava/io/InputStream;
    :try_end_2
    .catch Ljava/security/PrivilegedActionException; {:try_start_2 .. :try_end_2} :catch_1

    .line 373
    .end local v3           #classFound:Z
    .restart local v5       #is:Ljava/io/InputStream;
    :cond_1
    if-nez v5, :cond_2

    .line 377
    new-instance v9, Ljava/lang/ClassNotFoundException;

    invoke-direct {v9, p1}, Ljava/lang/ClassNotFoundException;-><init>(Ljava/lang/String;)V

    throw v9

    .line 355
    :catch_0
    move-exception v4

    .line 356
    .local v4, e:Ljava/net/MalformedURLException;
    const/4 v3, 0x0

    .restart local v3       #classFound:Z
    goto :goto_0

    .line 366
    .end local v5           #is:Ljava/io/InputStream;
    .end local v4           #e:Ljava/net/MalformedURLException;
    .end local v3           #classFound:Z
    :catch_1
    move-exception v9

    move-object v4, v9

    .line 370
    .local v4, e:Ljava/security/PrivilegedActionException;
    new-instance v9, Ljava/lang/ClassNotFoundException;

    invoke-virtual {v4}, Ljava/security/PrivilegedActionException;->getCause()Ljava/lang/Throwable;

    move-result-object v10

    invoke-direct {v9, p1, v10}, Ljava/lang/ClassNotFoundException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V

    throw v9

    .line 382
    .end local v4           #e:Ljava/security/PrivilegedActionException;
    .restart local v5       #is:Ljava/io/InputStream;
    :cond_2
    :try_start_3
    sget-boolean v9, Lorg/microemu/app/classloader/MIDletClassLoader;->traceClassLoading:Z

    if-eqz v9, :cond_3

    .line 383
    const-string v9, "Load MIDlet class"

    invoke-static {v9, p1}, Lorg/microemu/log/Logger;->info(Ljava/lang/String;Ljava/lang/String;)V

    .line 385
    :cond_3
    sget-boolean v9, Lorg/microemu/app/classloader/MIDletClassLoader;->instrumentMIDletClasses:Z

    if-eqz v9, :cond_5

    .line 386
    iget-object v9, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->config:Lorg/microemu/app/classloader/InstrumentationConfig;

    invoke-static {v5, v9}, Lorg/microemu/app/classloader/ClassPreprocessor;->instrument(Ljava/io/InputStream;Lorg/microemu/app/classloader/InstrumentationConfig;)[B

    move-result-object v0

    .line 387
    .local v0, byteCode:[B
    array-length v1, v0
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    .line 420
    .local v1, byteCodeLength:I
    :cond_4
    :try_start_4
    invoke-virtual {v5}, Ljava/io/InputStream;->close()V
    :try_end_4
    .catch Ljava/io/IOException; {:try_start_4 .. :try_end_4} :catch_3

    .line 427
    :goto_1
    invoke-virtual {p0, p1, v0, v12, v1}, Lorg/microemu/app/classloader/MIDletClassLoader;->defineClass(Ljava/lang/String;[BII)Ljava/lang/Class;

    move-result-object v9

    return-object v9

    .line 389
    .end local v0           #byteCode:[B
    .end local v1           #byteCodeLength:I
    :cond_5
    const/16 v2, 0x800

    .line 391
    .local v2, chunkSize:I
    const/16 v6, 0x4000

    .line 392
    .local v6, maxClassSizeSize:I
    const/16 v9, 0x800

    :try_start_5
    new-array v0, v9, [B
    :try_end_5
    .catchall {:try_start_5 .. :try_end_5} :catchall_0

    .line 393
    .restart local v0       #byteCode:[B
    const/4 v1, 0x0

    .line 397
    .restart local v1       #byteCodeLength:I
    :cond_6
    :goto_2
    :try_start_6
    array-length v9, v0

    sub-int/2addr v9, v1

    invoke-virtual {v5, v0, v1, v9}, Ljava/io/InputStream;->read([BII)I
    :try_end_6
    .catchall {:try_start_6 .. :try_end_6} :catchall_0
    .catch Ljava/io/IOException; {:try_start_6 .. :try_end_6} :catch_2

    move-result v8

    .line 401
    .local v8, retrived:I
    const/4 v9, -0x1

    if-eq v8, v9, :cond_4

    .line 404
    :try_start_7
    array-length v9, v0

    add-int/lit16 v9, v9, 0x800

    const/16 v10, 0x4000

    if-le v9, v10, :cond_7

    .line 405
    new-instance v9, Ljava/lang/ClassNotFoundException;

    new-instance v10, Ljava/lang/ClassFormatError;

    const-string v11, "Class object is bigger than 16 Kilobyte"

    invoke-direct {v10, v11}, Ljava/lang/ClassFormatError;-><init>(Ljava/lang/String;)V

    invoke-direct {v9, p1, v10}, Ljava/lang/ClassNotFoundException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V

    throw v9
    :try_end_7
    .catchall {:try_start_7 .. :try_end_7} :catchall_0

    .line 419
    .end local v2           #chunkSize:I
    .end local v6           #maxClassSizeSize:I
    .end local v0           #byteCode:[B
    .end local v1           #byteCodeLength:I
    .end local v8           #retrived:I
    :catchall_0
    move-exception v9

    .line 420
    :try_start_8
    invoke-virtual {v5}, Ljava/io/InputStream;->close()V
    :try_end_8
    .catch Ljava/io/IOException; {:try_start_8 .. :try_end_8} :catch_4

    .line 422
    :goto_3
    throw v9

    .line 398
    .restart local v0       #byteCode:[B
    .restart local v1       #byteCodeLength:I
    .restart local v2       #chunkSize:I
    .restart local v6       #maxClassSizeSize:I
    :catch_2
    move-exception v9

    move-object v4, v9

    .line 399
    .local v4, e:Ljava/io/IOException;
    :try_start_9
    new-instance v9, Ljava/lang/ClassNotFoundException;

    invoke-direct {v9, p1, v4}, Ljava/lang/ClassNotFoundException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V

    throw v9

    .line 408
    .end local v4           #e:Ljava/io/IOException;
    .restart local v8       #retrived:I
    :cond_7
    add-int/2addr v1, v8

    .line 409
    array-length v9, v0

    if-ne v9, v1, :cond_8

    .line 410
    array-length v9, v0

    add-int/lit16 v9, v9, 0x800

    new-array v7, v9, [B

    .line 411
    .local v7, newData:[B
    const/4 v9, 0x0

    const/4 v10, 0x0

    array-length v11, v0

    invoke-static {v0, v9, v7, v10, v11}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V

    .line 412
    move-object v0, v7

    .line 413
    goto :goto_2

    .end local v7           #newData:[B
    :cond_8
    array-length v9, v0

    if-ge v9, v1, :cond_6

    .line 414
    new-instance v9, Ljava/lang/ClassNotFoundException;

    new-instance v10, Ljava/lang/ClassFormatError;

    const-string v11, "Internal read error"

    invoke-direct {v10, v11}, Ljava/lang/ClassFormatError;-><init>(Ljava/lang/String;)V

    invoke-direct {v9, p1, v10}, Ljava/lang/ClassNotFoundException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V

    throw v9
    :try_end_9
    .catchall {:try_start_9 .. :try_end_9} :catchall_0

    .line 421
    .end local v2           #chunkSize:I
    .end local v6           #maxClassSizeSize:I
    .end local v8           #retrived:I
    :catch_3
    move-exception v9

    goto :goto_1

    .end local v0           #byteCode:[B
    .end local v1           #byteCodeLength:I
    :catch_4
    move-exception v10

    goto :goto_3
.end method

.method public getResource(Ljava/lang/String;)Ljava/net/URL;
    .locals 3
    .parameter "name"

    .prologue
    .line 252
    :try_start_0
    new-instance v1, Lorg/microemu/app/classloader/MIDletClassLoader$1;

    invoke-direct {v1, p0, p1}, Lorg/microemu/app/classloader/MIDletClassLoader$1;-><init>(Lorg/microemu/app/classloader/MIDletClassLoader;Ljava/lang/String;)V

    iget-object v2, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->acc:Ljava/security/AccessControlContext;

    invoke-static {v1, v2}, Ljava/security/AccessController;->doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, Ljava/net/URL;
    :try_end_0
    .catch Ljava/security/PrivilegedActionException; {:try_start_0 .. :try_end_0} :catch_0

    move-object v1, p0

    .line 265
    :goto_0
    return-object v1

    .line 261
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 265
    .local v0, e:Ljava/security/PrivilegedActionException;
    const/4 v1, 0x0

    goto :goto_0
.end method

.method public getResourceAsStream(Ljava/lang/String;)Ljava/io/InputStream;
    .locals 5
    .parameter "name"

    .prologue
    const/4 v4, 0x0

    .line 273
    invoke-virtual {p0, p1}, Lorg/microemu/app/classloader/MIDletClassLoader;->getResource(Ljava/lang/String;)Ljava/net/URL;

    move-result-object v1

    .line 274
    .local v1, url:Ljava/net/URL;
    if-nez v1, :cond_0

    move-object v2, v4

    .line 288
    .end local p0
    :goto_0
    return-object v2

    .line 279
    .restart local p0
    :cond_0
    :try_start_0
    new-instance v2, Lorg/microemu/app/classloader/MIDletClassLoader$2;

    invoke-direct {v2, p0, v1}, Lorg/microemu/app/classloader/MIDletClassLoader$2;-><init>(Lorg/microemu/app/classloader/MIDletClassLoader;Ljava/net/URL;)V

    iget-object v3, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->acc:Ljava/security/AccessControlContext;

    invoke-static {v2, v3}, Ljava/security/AccessController;->doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, Ljava/io/InputStream;
    :try_end_0
    .catch Ljava/security/PrivilegedActionException; {:try_start_0 .. :try_end_0} :catch_0

    move-object v2, p0

    goto :goto_0

    .line 284
    :catch_0
    move-exception v2

    move-object v0, v2

    .local v0, e:Ljava/security/PrivilegedActionException;
    move-object v2, v4

    .line 288
    goto :goto_0
.end method

.method protected declared-synchronized loadClass(Ljava/lang/String;Z)Ljava/lang/Class;
    .locals 3
    .parameter "name"
    .parameter "resolve"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/ClassNotFoundException;
        }
    .end annotation

    .prologue
    .line 198
    monitor-enter p0

    :try_start_0
    invoke-virtual {p0, p1}, Lorg/microemu/app/classloader/MIDletClassLoader;->findLoadedClass(Ljava/lang/String;)Ljava/lang/Class;
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    move-result-object v1

    .line 199
    .local v1, result:Ljava/lang/Class;
    if-nez v1, :cond_0

    .line 201
    :try_start_1
    invoke-virtual {p0, p1}, Lorg/microemu/app/classloader/MIDletClassLoader;->findClass(Ljava/lang/String;)Ljava/lang/Class;
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0
    .catch Ljava/lang/ClassNotFoundException; {:try_start_1 .. :try_end_1} :catch_0

    move-result-object v1

    .line 220
    :cond_0
    if-eqz p2, :cond_1

    .line 221
    :try_start_2
    invoke-virtual {p0, v1}, Lorg/microemu/app/classloader/MIDletClassLoader;->resolveClass(Ljava/lang/Class;)V
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    .line 223
    :cond_1
    monitor-exit p0

    return-object v1

    .line 205
    :catch_0
    move-exception v0

    .line 207
    .local v0, e:Ljava/lang/ClassNotFoundException;
    :try_start_3
    instance-of v2, v0, Lorg/microemu/app/classloader/MIDletClassLoader$LoadClassByParentException;

    if-nez v2, :cond_2

    iget-boolean v2, p0, Lorg/microemu/app/classloader/MIDletClassLoader;->delegatingToParent:Z

    if-eqz v2, :cond_0

    .line 208
    :cond_2
    sget-boolean v2, Lorg/microemu/app/classloader/MIDletClassLoader;->traceSystemClassLoading:Z

    if-eqz v2, :cond_3

    .line 209
    const-string v2, "Load system class"

    invoke-static {v2, p1}, Lorg/microemu/log/Logger;->info(Ljava/lang/String;Ljava/lang/String;)V

    .line 213
    :cond_3
    const/4 v2, 0x0

    invoke-super {p0, p1, v2}, Ljava/net/URLClassLoader;->loadClass(Ljava/lang/String;Z)Ljava/lang/Class;

    move-result-object v1

    .line 214
    .restart local v1       #result:Ljava/lang/Class;
    if-nez v1, :cond_0

    .line 215
    new-instance v2, Ljava/lang/ClassNotFoundException;

    invoke-direct {v2, p1}, Ljava/lang/ClassNotFoundException;-><init>(Ljava/lang/String;)V

    throw v2
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    .line 198
    .end local v0           #e:Ljava/lang/ClassNotFoundException;
    .end local v1           #result:Ljava/lang/Class;
    :catchall_0
    move-exception v2

    monitor-exit p0

    throw v2
.end method
